<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Centermod extends CI_Model 
{

    function __construct()
    {
        parent::__construct();
    	$this->load->database();

	}
	
//################## commun function################################
	public function updatetemplate($tablename,$data,$where)
		{
				
			$str = $this->db->update_string($tablename, $data, $where);
			
			$query = $this->db->query($str);
			//print_r($query);
			
		}	
		
	public function insertetemplate($tablename,$data)
		{
				
			$str = $this->db->insert_string($tablename, $data);
			 
			$query = $this->db->query($str);
			$idinsert=$this->db->insert_id();
			return $idinsert;
			
		}	

		
		
//######################### end commun function###########################

  	public function listfeatures()
	{
		$query = $this->db->query("select * FROM web_travel where  featureshowitems != 0 order by featureshowitems");
		return $query->result_array();
	}
	
	
	public function listgroup()
	{
	  	$query=$this->db->query("select * from web_group");
  		return $query->result_array();
	}
	

	public function getgroupbyid($idgroup)
  		{
  			$query=$this->db->query("select * from web_group where idweb_group=?",array($idgroup));
  			
  			return $query->result_array();
  		}

  	public function gettoursbyidgroup($idgroup)
  	{
  		$query=$this->db->query("SELECT* FROM web_travel where web_group_idweb_group=?",array($idgroup));
  		return $query->result_array();
  	}
  	
	public function getwebtourswithpricebyid($idtour)
  		{
  			$query=$this->db->query("
  			SELECT
				idweb_travel, 
				name_en, 
				name_fr, 
				subtitle_en,
				subtitle_fr,
				subtitle_cn,
				name_cn, desc_en, 
				desc_fr, desc_cn, 
				
				price_r, 
				price_red, 
				place_dispo, 
				bookingcode,
				featureshowitems, 
				with_room, 
				web_group_idweb_group,
				 idwith_room_price ,
				 reg_1 ,
				 reg_2 ,
				 reg_3 ,
				 reg_4 ,
				 reg_child ,
				 reg_ad ,
				 member_1 ,
				 member_2 ,
				 member_3 ,
				 member_4 ,
				 member_child ,
				 member_ad ,
				 line_1 ,
				 line_2 ,
				 line_3 ,
				 line_4 ,
				 line_child ,
				 line_ad, 
				 reg_child_1 ,
				 member_child_1 ,
				 line_child_1 
				 FROM  web_travel as wt 
				 inner join with_room_price as wp 
				 on wt.idweb_travel=wp.web_travel_idweb_travel 
				 where idweb_travel=?"
  				 ,array($idtour));
		  			
		  			return $query->result_array();
  		}
  		
  		
  // online booking 

  	//########################## liste tour ##################################

	
//liste tour by code
	public function ltourbycode($code)
		{
			$codefiltre=trim($code);	
			$query = $this->db->query("SELECT * FROM tours WHERE code like '$codefiltre%' and date >=now() order by date  desc");
			return $query->result_array();			 
						
		}	

//liste forfait by idtours		
	public function lforfaitbyid($idtour)
		{
				
			$query = $this->db->query("SELECT * FROM forfaits where fk_idtours=$idtour");
			return $query->result_array();			 
						
		}	
		
//listinfo de tours 
	public function ltourbyid($id)
		{
				
			$query = $this->db->query("select * from tours where idtours=$id");
			return $query->result_array();			 
						
		}	
		
 //list bus 
 	public function lbus($idtour)
		{
				
			$query = $this->db->query("SELECT *FROM  bus WHERE fk_idtours =$idtour");
			return $query->result_array();			
		}
		
		
//add new xiaoming 2012-11-20
 	public function dispoplace($idtour)
 	{
 			$query = $this->db->query("SELECT  sum(seatavaible) as total  FROM  bus WHERE fk_idtours =$idtour");
			return $query->result_array();	
 	}		
		
 	
	public function selectforfait($idtour,$chambretype)
		{
				
			$query = $this->db->query("SELECT * FROM forfaits where fk_idtours=$idtour and chambretype=$chambretype");
			return $query->result_array();			 
						
		}	
 	
 	public function cketranction($idtransc)
 	{
 		$query = $this->db->query("select * from transcation where idtransc='$idtransc'");
 		return $query->result_array();		
 	}

		
		
// end		
  		
  		
	
}
